home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / include / dynP.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-24  |  1.9 KB  |  72 lines

  1. /*
  2.  * This file is part of libdyn.a, the C Dynamic Object library.  It
  3.  * contains the private header file.
  4.  *
  5.  * There are no restrictions on this code; however, if you make any
  6.  * changes, I request that you document them so that I do not get
  7.  * credit or blame for your modifications.
  8.  *
  9.  * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
  10.  * and MIT-Project Athena, 1989.
  11.  */
  12.  
  13.  
  14. /*
  15.  * dynP.h -- private header file included by source files for libdyn.a.
  16.  */
  17.  
  18. #ifndef _DynP_h
  19. #define _DynP_h
  20.  
  21. #include "dyn.h"
  22.  
  23. /*
  24.  * Rep invariant:
  25.  * 1) el_size is the number of bytes per element in the object
  26.  * 2) num_el is the number of elements currently in the object.  It is
  27.  * one higher than the highest index at which an element lives.
  28.  * 3) size is the number of elements the object can hold without
  29.  * resizing.  num_el <= index.
  30.  * 4) inc is a multiple of the number of elements the object grows by
  31.  * each time it is reallocated.
  32.  */
  33.  
  34. typedef struct _DynObject {
  35.      DynPtr    array;
  36.      int    el_size, num_el, size, inc;
  37.      char    debug, paranoid;
  38. } DynObjectRecP, *DynObjectP;
  39.  
  40. /* Internal functions */
  41. int _DynRealloc();
  42.  
  43. #define _DynResize(obj, req) \
  44.      ((obj)->size > (req) ? DYN_OK : \
  45.      (_DynRealloc((obj), (((req) - (obj)->size) / (obj)->inc) + 1)))
  46.  
  47. /* external (C library) functions */
  48. #ifndef __STDC__
  49. extern char *malloc ();
  50. extern char *realloc ();
  51. extern void free ();
  52. extern int fprintf ();
  53. extern void bzero ();
  54. extern void bcopy ();
  55. #else
  56. #include <stdio.h>
  57. #ifdef _POSIX_SOURCE
  58. #include <stdlib.h>
  59. #else
  60. extern void *malloc (unsigned);
  61. extern void *realloc (void *, unsigned);
  62. extern void free (void *);
  63. extern int fprintf (FILE *, const char *, ...);
  64. extern void bzero (void *, unsigned);
  65. extern void memcpy (void *, void *, unsigned);
  66. #define bcopy(src,dest,size)    memcpy(dest,src,size)
  67. #endif
  68. #endif
  69.  
  70. #endif /* _DynP_h */
  71. /* DON'T ADD STUFF AFTER THIS #endif */
  72.